Click to See Complete Forum and Search --> : Problem with attribute in custom tag


Ghoul
06-16-2005, 04:55 AM
Hi!

I'm developing custom tag. This tag is specialised form element. This tag must accept an attribute that is another tag. And the latter tag does not work at all. :(

The code of tag:
public class FormTag extends TagSupport {

// ***

/*
* Render the beginning of this form.
*
* @exception JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
String result = "";

result = "<form ";

result += "name=\"testForm\" ";
result += "method=\"post\" ";

if(action != null) {
result += " action=\"" + action + "\" ";
}

result += ">";

// Print this value to our output writer
JspWriter writer = pageContext.getOut();
try {
writer.println(result);
} catch(Exception e) {
throw new RuntimeException(e);
}

return (EVAL_BODY_INCLUDE);
}

// ***

}

The corresponding part of jsp:


<p:form action="<portlet:actionURL/>">
<input type="text" name="firstName" value="">
<br>
<input type="submit" value="Submit">
</p:form>

All taglibs are declared. And everything is OK if I use ordinary form element. But a strongly need that custom tag. :cool:

The source of resulting HTML is:

<form name="testForm" method="post" action="<portlet:actionURL/>" >
<input type="text" name="firstName" value="">
<br>
<input type="submit" value="Submit">
</form>


It looks like action attribute is not processed.

Any ideas? :confused:

Thanks

buntine
06-16-2005, 01:17 PM
Try using an HTML form.

<form action="<portlet:actionURL/>" method="post">
<input type="text" name="firstName" value="">
<br>
<input type="submit" value="Submit">
</form>

Regards.

Oak
06-17-2005, 01:03 AM
You are trying to nest a tag within quotation marks. The engine that turns the page from tags into html will think you want the output to literally be <portlet:actionURL/> rather than the generated equivalent.

You may need to access the variable with scriptlets <%= %> however, you should really find a tag for the platform that you are using that support mapping to a dynamic value. In struts this is <html:form>

Good luck with it :)

Ghoul
06-17-2005, 08:58 AM
Thank you for your replies!

I worked around it by replacing <portlet:actionURL/> with response.createActionURL().toString() . Where response is instance of RenderResponse.
It works fine :)