I'll try and if succeeded I'll contribute back to Openxava.
Let me use this moment to express you my admiration for your work. I have been observing all your participation in this project and is a case to manage so much work
JG
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
> I have been observing all your participation in this project and
> is a case to manage so much work
Oh! Thanks! To meet someone that thinks that I do "so much work" is a little pleasure. :)
> I have done to have an editor for a web url that allows a link to be clicked
Well done! And thanks for put your editor here, in the forum.
Instead of copy, paste and modify the textEditors.jsp would be better to include (using <%@ include file="textEditor.jsp"%> as in moneyEditor.jsp) the textEditor.jsp and add the link after, in order to follow the DRY principle. If you do so, I would include your improvement in OX distribution.
Cheers
Javi
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi everybody,
I have a url attribute :
@Stereotype("WEBURL")
@Action("weburl.showurl")
private String webURL;
and I would like to navigate from this attribute to the corresponding site. My first solutions don't work well.
Thanks for any suggestion
Granado
Hi Joao,
the better option (I think) is improve the WEBURL in order to use an editor with a link "go". Look at:
http://openxava.wikispaces.com/customizing_en#toc2
Though this case is very easy, you can create your editor including textEditor.jsp in your editor and after adding the link.
After it works for you, would be nice, if you would contribute back the improvement to OpenXava.
Cheers
Javi
Thanks Javier,
I'll try and if succeeded I'll contribute back to Openxava.
Let me use this moment to express you my admiration for your work. I have been observing all your participation in this project and is a case to manage so much work
JG
Hi Joao,
> I have been observing all your participation in this project and
> is a case to manage so much work
Oh! Thanks! To meet someone that thinks that I do "so much work" is a little pleasure. :)
Though, OpenXava is a shared project, with near to 30 authors:
http://www.gestion400.com/web/guest/credits
Cheers
Javi
Here is what I have done to have an editor for a web url that allows a link to be clicked to show the text's site (I am using openxava 3.0.3):
First) In <myproject>/xava/editors.xml I have added this at the beginning of the file to associate the stereotype “WEBURL” with this specific editor:
<editors>
<editor name="WebURL" url="webUrlEditor.jsp">
<for-stereotype stereotype="WEBURL"/>
</editor>
….
</editors>
Second) I have created the editor “webUrlEditor.jsp” in folder <myproject>/web/editors/, where all the other editors are:
<%@ page import="org.openxava.model.meta.MetaProperty" %>
<%@ page import="org.openxava.util.Strings" %>
<%@ page import="org.openxava.util.Align" %>
<%@ page import="org.openxava.util.Labels" %>
<jsp:useBean id="style" class="org.openxava.web.style.Style" scope="request"/>
<%
String propertyKey = request.getParameter("propertyKey");
MetaProperty p = (MetaProperty) request.getAttribute(propertyKey);
String fvalue = (String) request.getAttribute(propertyKey + ".fvalue");
String align = p.isNumber()?"style='text-align:right'":"";
boolean editable="true".equals(request.getParameter("editable"));
String disabled=editable?"":"disabled";
String script = request.getParameter("script");
boolean label = org.openxava.util.XavaPreferences.getInstance().isReadOnlyAsLabel();
String smaxSize = request.getParameter("maxSize");
int maxSize = 0;
if (!org.openxava.util.Is.emptyString(smaxSize)) {
maxSize = Integer.parseInt(smaxSize);
}
else {
maxSize = org.openxava.util.XavaPreferences.getInstance().getMaxSizeForTextEditor();
}
int size = p.getSize() > maxSize?maxSize:p.getSize();
int maxLength = p.getSize();
if (p.isNumber()) {
if (p.getScale() > 0) {
int sizeIncrement = (size - 1) / 3 + 2; // The points/commas for thousands + point/comma for decimal + minus sign
size += sizeIncrement;
maxLength += sizeIncrement;
}
String integer = p.getScale() == 0?"true":"false";
script = script + " onkeypress='return validateNumeric(event, " + p.getSize() + ", " + integer + ")' ";
}
boolean fillWithZeros = "true".equals(request.getParameter("fillWithZeros"));
if (fillWithZeros && fvalue.length() > 0) {
fvalue = Strings.fix(fvalue, size, Align.RIGHT, '0');
}
if (editable || !label) {
%>
<table border="0" cellpadding="0" cellspacing="0">
<tr><td>
<input name="<%=propertyKey%>" class=<%=style.getEditor()%>
type="text"
title="<%=p.getDescription(request)%>"
<%=align%>
maxlength="<%=maxLength%>"
size="<%=size%>"
value="<%=Strings.change(fvalue, "\"", """)%>"
<%=disabled%>
<%=script%>
/><td>
<a href="<%=fvalue%>" target="_blank" ><img type="image" title="<%=org.openxava.util.XavaResources.getString("gotourl", org.openxava.util.Locales.getCurrent())%>" border="0" src="images/view.gif" alt="<%=Labels.get("GO", org.openxava.util.Locales.getCurrent())%>"></img></a>
</table>
<%
} else {
%>
<a href="<%=fvalue%>" ><%=fvalue%></a>
<%
}
%>
<% if (!editable) { %>
<input type="hidden" name="<%=propertyKey%>" value="<%=fvalue%>">
<% } %>
Third) To localize the editor to Portuguese I have created an entry in <myproject>-labels_pt.properties:
….
GO=IR
….
Fourth) to localize the editor to Portuguese I have created an entry in <myproject>-messages_pt.properties:
gotourl=Ir para sitio
mailto=enviar mail
That's all. After this I have done something alike for the stereotype EMAIL.
Here is the code for mailEditor.jsp:
<%@ page import="org.openxava.model.meta.MetaProperty" %>
<%@ page import="org.openxava.util.Strings" %>
<%@ page import="org.openxava.util.Align" %>
<%@ page import="org.openxava.util.Labels" %>
<jsp:useBean id="style" class="org.openxava.web.style.Style" scope="request"/>
<%
String propertyKey = request.getParameter("propertyKey");
MetaProperty p = (MetaProperty) request.getAttribute(propertyKey);
String fvalue = (String) request.getAttribute(propertyKey + ".fvalue");
String align = p.isNumber()?"style='text-align:right'":"";
boolean editable="true".equals(request.getParameter("editable"));
String disabled=editable?"":"disabled";
String script = request.getParameter("script");
boolean label = org.openxava.util.XavaPreferences.getInstance().isReadOnlyAsLabel();
String smaxSize = request.getParameter("maxSize");
int maxSize = 0;
if (!org.openxava.util.Is.emptyString(smaxSize)) {
maxSize = Integer.parseInt(smaxSize);
}
else {
maxSize = org.openxava.util.XavaPreferences.getInstance().getMaxSizeForTextEditor();
}
int size = p.getSize() > maxSize?maxSize:p.getSize();
int maxLength = p.getSize();
if (p.isNumber()) {
if (p.getScale() > 0) {
int sizeIncrement = (size - 1) / 3 + 2; // The points/commas for thousands + point/comma for decimal + minus sign
size += sizeIncrement;
maxLength += sizeIncrement;
}
String integer = p.getScale() == 0?"true":"false";
script = script + " onkeypress='return validateNumeric(event, " + p.getSize() + ", " + integer + ")' ";
}
boolean fillWithZeros = "true".equals(request.getParameter("fillWithZeros"));
if (fillWithZeros && fvalue.length() > 0) {
fvalue = Strings.fix(fvalue, size, Align.RIGHT, '0');
}
if (editable || !label) {
%>
<table border="0" cellpadding="0" cellspacing="0">
<tr><td>
<input name="<%=propertyKey%>" class=<%=style.getEditor()%>
type="text"
title="<%=p.getDescription(request)%>"
<%=align%>
maxlength="<%=maxLength%>"
size="<%=size%>"
value="<%=Strings.change(fvalue, "\"", """)%>"
<%=disabled%>
<%=script%>
/><td>
<a href="mailto:<%=fvalue%>" target="_blank" ><img type="image" title="<%=org.openxava.util.XavaResources.getString("mailto", org.openxava.util.Locales.getCurrent())%>" border="0" src="images/view.gif" alt="<%=Labels.get("GO", org.openxava.util.Locales.getCurrent())%>"></img></a>
</table>
<%
} else {
%>
<a href="<%=fvalue%>" ><%=fvalue%></a>
<%
}
%>
<% if (!editable) { %>
<input type="hidden" name="<%=propertyKey%>" value="<%=fvalue%>">
<% } %>
Hi Joao,
> I have done to have an editor for a web url that allows a link to be clicked
Well done! And thanks for put your editor here, in the forum.
Instead of copy, paste and modify the textEditors.jsp would be better to include (using <%@ include file="textEditor.jsp"%> as in moneyEditor.jsp) the textEditor.jsp and add the link after, in order to follow the DRY principle. If you do so, I would include your improvement in OX distribution.
Cheers
Javi
Hi Javi, thanks for your tip.
webUrlEditor.jsp:
<%@include file="textEditor.jsp"%>
<%@ page import="org.openxava.util.Labels" %>
<a href="<%=fvalue%>" target="_blank" ><img type="image" title="<%=org.openxava.util.XavaResources.getString("gotourl", org.openxava.util.Locales.getCurrent())%>" border="0" src="images/view.gif" alt="<%=Labels.get("GO", org.openxava.util.Locales.getCurrent())%>"></img></a>
mailEditor.jsp:
<%@include file="textEditor.jsp" %>
<%@ page import="org.openxava.util.Labels" %>
<a href="mailto:<%=fvalue%>" target="_blank" ><img type="image" title="<%=org.openxava.util.XavaResources.getString("mailto", org.openxava.util.Locales.getCurrent())%>" border="0" src="images/view.gif" alt="<%=Labels.get("GO", org.openxava.util.Locales.getCurrent())%>"></img></a>
Cheers
Joao
That's better!
Can I include your code in OpenXava distribution.