You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Zoran Avtarovski <zo...@sparecreative.com> on 2008/04/10 09:18:46 UTC

Advice on dynamic form elements

Hi,

We porting/upgrading a relatively simple survey tool over to struts2 from an
old php version.

The tool manages questions which can one of a fixed type (radio, drop,
checkbox, text) and then persists responses to DB.
Where I need some advice is how to implement the struts 2 display mechanism.

I figure there are two options:

1. Write a custom tag which takes the question as an attribute. Something
like <s:question value=²%{question}² />

2. I could have a small jsp fragment that I would include to render the
appropriate html.

I figured I¹d do something like :

<s:iterator value=²questions² id=²question²>
<s:push value=²%{question}²>
    <s:include value=²pagefragment.jspf²/>
</s:push>
</s:iterator>

And pagefragment.jspf would have some logic and use the appropriate form
tags to render the HTML.

I was looking for some input into what people think.


Z.


Re: Advice on dynamic form elements

Posted by Rene Gielen <gi...@it-neering.net>.
You could also think of using a component, which would help to avoid writing
a tag with tld generation and all that:
http://struts.apache.org/2.0.11.1/docs/component.html


Sparecreative wrote:
> 
> Thanks Laurie,
> 
> I actually thought of a tag file but thought it might be the lazy way out.
> We actually use them extensively for dropping in html components.
> 
> I feel a lot better now.
> 
> Thanks
> 
> Z.
>> 
>> Zoran Avtarovski wrote:
>>> > Hi,
>>> > 
>>> > We porting/upgrading a relatively simple survey tool over to struts2
>>> from
>>> an
>>> > old php version.
>>> > 
>>> > The tool manages questions which can one of a fixed type (radio, drop,
>>> > checkbox, text) and then persists responses to DB.
>>> > Where I need some advice is how to implement the struts 2 display
>>> mechanism..
>>> > 
>>> > I figure there are two options:
>>> > 
>>> > 1. Write a custom tag which takes the question as an attribute.
>>> Something
>>> > like <s:question value=²%{question}² />
>> 
>> Well, it wouldn't be s:question unless you're planning on modifying the
>> Struts taglib ;=) but a custom tag would be one way to do this. Using a
>> .tag file might be the easiest, depending how complex your rendering
>> logic is.
>> 
>>> > 2. I could have a small jsp fragment that I would include to render
>>> the
>>> > appropriate html.
>>> > 
>>> > I figured I¹d do something like :
>>> > 
>>> > <s:iterator value=²questions² id=²question²>
>>> > <s:push value=²%{question}²>
>>> >     <s:include value=²pagefragment.jspf²/>
>>> > </s:push>
>>> > </s:iterator>
>> 
>> The tag-based solution is obviously more concise to use, although the
>> s:push is unnecessary here (s:iterator pushes the value automatically).
>> 
>>> > And pagefragment.jspf would have some logic and use the appropriate
>>> form
>>> > tags to render the HTML.
>> 
>> If you can express what you want to do in a JSP, it should be trivial to
>> do it in a .tag file, which would give you the more concise usage.
>> Otherwise, a custom tag may be worth it.
>> 
>> L.
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>> 
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Advice-on-dynamic-form-elements-tp16603555p16674012.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Advice on dynamic form elements

Posted by Zoran Avtarovski <zo...@sparecreative.com>.
Thanks Laurie,

I actually thought of a tag file but thought it might be the lazy way out.
We actually use them extensively for dropping in html components.

I feel a lot better now.

Thanks

Z.
> 
> Zoran Avtarovski wrote:
>> > Hi,
>> > 
>> > We porting/upgrading a relatively simple survey tool over to struts2 from
>> an
>> > old php version.
>> > 
>> > The tool manages questions which can one of a fixed type (radio, drop,
>> > checkbox, text) and then persists responses to DB.
>> > Where I need some advice is how to implement the struts 2 display
>> mechanism..
>> > 
>> > I figure there are two options:
>> > 
>> > 1. Write a custom tag which takes the question as an attribute. Something
>> > like <s:question value=²%{question}² />
> 
> Well, it wouldn't be s:question unless you're planning on modifying the
> Struts taglib ;=) but a custom tag would be one way to do this. Using a
> .tag file might be the easiest, depending how complex your rendering
> logic is.
> 
>> > 2. I could have a small jsp fragment that I would include to render the
>> > appropriate html.
>> > 
>> > I figured I¹d do something like :
>> > 
>> > <s:iterator value=²questions² id=²question²>
>> > <s:push value=²%{question}²>
>> >     <s:include value=²pagefragment.jspf²/>
>> > </s:push>
>> > </s:iterator>
> 
> The tag-based solution is obviously more concise to use, although the
> s:push is unnecessary here (s:iterator pushes the value automatically).
> 
>> > And pagefragment.jspf would have some logic and use the appropriate form
>> > tags to render the HTML.
> 
> If you can express what you want to do in a JSP, it should be trivial to
> do it in a .tag file, which would give you the more concise usage.
> Otherwise, a custom tag may be worth it.
> 
> L.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 



Re: Advice on dynamic form elements

Posted by Laurie Harper <la...@holoweb.net>.
Zoran Avtarovski wrote:
> Hi,
> 
> We porting/upgrading a relatively simple survey tool over to struts2 from an
> old php version.
> 
> The tool manages questions which can one of a fixed type (radio, drop,
> checkbox, text) and then persists responses to DB.
> Where I need some advice is how to implement the struts 2 display mechanism..
> 
> I figure there are two options:
> 
> 1. Write a custom tag which takes the question as an attribute. Something
> like <s:question value=²%{question}² />

Well, it wouldn't be s:question unless you're planning on modifying the 
Struts taglib ;=) but a custom tag would be one way to do this. Using a 
.tag file might be the easiest, depending how complex your rendering 
logic is.

> 2. I could have a small jsp fragment that I would include to render the
> appropriate html.
> 
> I figured I¹d do something like :
> 
> <s:iterator value=²questions² id=²question²>
> <s:push value=²%{question}²>
>     <s:include value=²pagefragment.jspf²/>
> </s:push>
> </s:iterator>

The tag-based solution is obviously more concise to use, although the 
s:push is unnecessary here (s:iterator pushes the value automatically).

> And pagefragment.jspf would have some logic and use the appropriate form
> tags to render the HTML.

If you can express what you want to do in a JSP, it should be trivial to 
do it in a .tag file, which would give you the more concise usage. 
Otherwise, a custom tag may be worth it.

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org