Solved

Struts related Questions

Posted on 2004-09-03
23
1,863 Views
Last Modified: 2008-02-01
2 Struts related Q's :-)

(1)

<TD colspan="3" >
<html:radio property="displayPeriod" value="days"> Days </html:radio>
<html:radio property="displayPeriod" value="months"> Months </html:radio>
<html:radio property="displayPeriod" value="years"> Years </html:radio>
</TD>

In the above struts - tags, how can i make "Days" to be checked by default. I tried setting
String displayPeriod = "days"; in my ActionForm, but it didnt worked.

(2)

<logic:iterate name="DateRange" id="Date">
          <td class="tdHeader"> <bean:write name="Date" property="label" /> </td>
</logic:iterate>

In the above, "DateRange" is a set of dates that are displayed in the <td>. Now, if the date is a weekend, i want a different *CLASS* for td.

i.e.

if(Date != weekend)
    <td class="tdNormal"> <bean:write name="Date" property="label" /> </td>
else
    <td class="tdWeekend"> <bean:write name="Date" property="label" /> </td>

Thanks.
0
Comment
Question by:ldbkutty
  • 11
  • 7
  • 3
  • +1
23 Comments
 
LVL 37

Assisted Solution

by:zzynx
zzynx earned 100 total points
ID: 11973552
Struts Tip #16 - How to (not) check a radio button :
http://www.jguru.com/faq/view.jsp?EID=1028442
0
 
LVL 35

Expert Comment

by:girionis
ID: 11974176
> In the above, "DateRange" is a set of dates that are displayed in the
> <td>. Now, if the date is a weekend, i want a different *CLASS* for td.
>
> i.e.
>
> if(Date != weekend)
>     <td class="tdNormal"> <bean:write name="Date" property="label" /> </td>
> else
>     <td class="tdWeekend"> <bean:write name="Date" property="label" /> </td>
>
> Thanks.


What type if the "Date"? If it is string you might as well do:

if(Date.equals("Saturday") || Date.equals("Sunday"))
    <td class="tdWeekend"> <bean:write name="Date" property="label" /> </td>
else
    <td class="tdNormal"> <bean:write name="Date" property="label" /> </td>
0
 
LVL 35

Expert Comment

by:girionis
ID: 11974257
Ah... is is a java.util.Date? You could do:

GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
if (dayOfWeek == 1 || dayOfWeek == 7) // 1 is sunday 7 is saturday
{
    <td class="tdWeekend"> <bean:write name="Date" property="label" /> </td>
}
else
    <td class="tdNormal"> <bean:write name="Date" property="label" /> </td>
0
 
LVL 16

Assisted Solution

by:suprapto45
suprapto45 earned 200 total points
ID: 11974583
Hello,

1. Well, if you want to check the radio button by default, you have to set it from the ActionForm that you run before the .jsp is loaded. However, you must ensure that displayPeriod is in the right form. I think that you should have the <html:form action=blah.do>

<TD colspan="3" >
<html:radio property="displayPeriod" value="days"> Days </html:radio>
<html:radio property="displayPeriod" value="months"> Months </html:radio>
<html:radio property="displayPeriod" value="years"> Years </html:radio>
</TD>

In the ActionForm, you have to set like this:
// Java codes here
yourForm.setDisplayPeriod("days");



0
 
LVL 16

Assisted Solution

by:suprapto45
suprapto45 earned 200 total points
ID: 11974644
For the second question, you can either use JSTL tag or <logic:equal>

<logic:equal name="Date" value="whatYouWant (Saturday or Sunday)">
    <td class="tdNormal"> <bean:write name="Date" property="label" /> </td>
</logic:equal>

<logic:notEqual name="Date"  value="whatYouWant (Saturday or Sunday)">
    <td class="tdWeekend"> <bean:write name="Date" property="label" /> </td>
</logic:notEqual>

Well, I hope that helps you
0
 
LVL 32

Author Comment

by:ldbkutty
ID: 11992772
sorry, my weekend took a long time...

is it possible to use more than one value check in <logic:equal ...> tag. something like:

<logic:notEqual name="Date"  value="1 || 2">
    <td class="tdWeekend"> <bean:write name="Date" property="label" /> </td>
</logic:notEqual>

i heard its not possible. Is it so or any other alternatives ?
0
 
LVL 35

Expert Comment

by:girionis
ID: 11994199
Not sure if it is possible but you can use the jstl (http://www.javaworld.com/javaworld/jw-02-2003/jw-0228-jstl.html) and do something like:

<c:if test ${Date == 1 OR Date == 2}><td class="tdWeekend"> <bean:write name="Date" property="label" /> </td></c:if>
0
 
LVL 32

Author Comment

by:ldbkutty
ID: 11995052
girinois,

After deploying JSTL, i am getting:

Unable to load tag handler class "org.apache.taglibs.standard.tag.rt.core.WhenTag" for tag "c:when"

( i tried with <c:choose><c:when>...</c:when><c:otherwise>...</c:otherwise></c:choose> )

but i do have that WhenTag class in my "standard.jar" file and i included it in the 'lib' folder.

Any ideas ?
0
 
LVL 32

Author Comment

by:ldbkutty
ID: 11995060
actually, i am not able to include any tags.

<c:if> throws:

Unable to load tag handler class "org.apache.taglibs.standard.tag.rt.core.IfTag" for tag "c:if"

but my eclipse editor successfully showed me all the tags.
0
 
LVL 35

Expert Comment

by:girionis
ID: 11995188
Ehm.. I am not sure what's going on, you probably have misconfigured the JSTL. Have you followed the instructions in the link I posted?
0
 
LVL 32

Author Comment

by:ldbkutty
ID: 11995258
alrite, i managed it,...but :

<logic:iterate name="DateRange" id="Date">
                <c:choose>
                      <c:when test='${Date == "1" || Date == "7"}'>
                            hai
                      </c:when>
                      <c:otherwise>
                            hallo
                      </c:otherwise>
                </c:choose>
</logic:iterate>

always gives me the output:  hallo

what should i give exactly in the "test" ?

I need to generate the <c:when ...> for this:

<logic:equal name="Date" property="dayOfWeek" value="1">
                      <td id="weekends" class="tdWeekend"> <bean:write name="Date" property="label" /> </td>
                </logic:equal>
                <logic:notEqual name="Date" property="dayOfWeek" value="1">
                      <td class="tdHeader"> <bean:write name="Date" property="label" /> </td>
                </logic:notEqual>

Thanks.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 35

Expert Comment

by:girionis
ID: 11995282
Try this:

 Comment from zzynx
Date: 09/03/2004 03:12PM GMT
ID: 11973552
 Comment  


Struts Tip #16 - How to (not) check a radio button :
http://www.jguru.com/faq/view.jsp?EID=1028442
 
Comment from girionis
Date: 09/03/2004 04:01PM GMT
ID: 11974176
 Your Comment  


> In the above, "DateRange" is a set of dates that are displayed in the
> <td>. Now, if the date is a weekend, i want a different *CLASS* for td.
>
> i.e.
>
> if(Date != weekend)
>     <td class="tdNormal"> <bean:write name="Date" property="label" /> </td>
> else
>     <td class="tdWeekend"> <bean:write name="Date" property="label" /> </td>
>
> Thanks.


What type if the "Date"? If it is string you might as well do:

if(Date.equals("Saturday") || Date.equals("Sunday"))
    <td class="tdWeekend"> <bean:write name="Date" property="label" /> </td>
else
    <td class="tdNormal"> <bean:write name="Date" property="label" /> </td>

 
Comment from girionis
Date: 09/03/2004 04:08PM GMT
ID: 11974257
 Your Comment  


Ah... is is a java.util.Date? You could do:

GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
if (dayOfWeek == 1 || dayOfWeek == 7) // 1 is sunday 7 is saturday
{
    <td class="tdWeekend"> <bean:write name="Date" property="label" /> </td>
}
else
    <td class="tdNormal"> <bean:write name="Date" property="label" /> </td>

 
Comment from suprapto45
Date: 09/03/2004 04:40PM GMT
ID: 11974583
 Comment  


Hello,

1. Well, if you want to check the radio button by default, you have to set it from the ActionForm that you run before the .jsp is loaded. However, you must ensure that displayPeriod is in the right form. I think that you should have the <html:form action=blah.do>

<TD colspan="3" >
<html:radio property="displayPeriod" value="days"> Days </html:radio>
<html:radio property="displayPeriod" value="months"> Months </html:radio>
<html:radio property="displayPeriod" value="years"> Years </html:radio>
</TD>

In the ActionForm, you have to set like this:
// Java codes here
yourForm.setDisplayPeriod("days");




 
Comment from suprapto45
Date: 09/03/2004 04:45PM GMT
ID: 11974644
 Comment  


For the second question, you can either use JSTL tag or <logic:equal>

<logic:equal name="Date" value="whatYouWant (Saturday or Sunday)">
    <td class="tdNormal"> <bean:write name="Date" property="label" /> </td>
</logic:equal>

<logic:notEqual name="Date"  value="whatYouWant (Saturday or Sunday)">
    <td class="tdWeekend"> <bean:write name="Date" property="label" /> </td>
</logic:notEqual>

Well, I hope that helps you
 
Comment from ldbkutty
Date: 09/06/2004 10:37PM GMT
ID: 11992772
 Author Comment  


sorry, my weekend took a long time...

is it possible to use more than one value check in <logic:equal ...> tag. something like:

<logic:notEqual name="Date"  value="1 || 2">
    <td class="tdWeekend"> <bean:write name="Date" property="label" /> </td>
</logic:notEqual>

i heard its not possible. Is it so or any other alternatives ?
 
Comment from girionis
Date: 09/07/2004 06:44AM GMT
ID: 11994199
 Your Comment  


Not sure if it is possible but you can use the jstl (http://www.javaworld.com/javaworld/jw-02-2003/jw-0228-jstl.html) and do something like:

<c:if test ${Date == 1 OR Date == 2}><td class="tdWeekend"> <bean:write name="Date" property="label" /> </td></c:if>
 
Comment from ldbkutty
Date: 09/07/2004 09:45AM GMT
ID: 11995052
 Author Comment  


girinois,

After deploying JSTL, i am getting:

Unable to load tag handler class "org.apache.taglibs.standard.tag.rt.core.WhenTag" for tag "c:when"

( i tried with <c:choose><c:when>...</c:when><c:otherwise>...</c:otherwise></c:choose> )

but i do have that WhenTag class in my "standard.jar" file and i included it in the 'lib' folder.

Any ideas ?
 
Comment from ldbkutty
Date: 09/07/2004 09:47AM GMT
ID: 11995060
 Author Comment  


actually, i am not able to include any tags.

<c:if> throws:

Unable to load tag handler class "org.apache.taglibs.standard.tag.rt.core.IfTag" for tag "c:if"

but my eclipse editor successfully showed me all the tags.
 
Comment from girionis
Date: 09/07/2004 10:17AM GMT
ID: 11995188
 Your Comment  


Ehm.. I am not sure what's going on, you probably have misconfigured the JSTL. Have you followed the instructions in the link I posted?
 
Comment from ldbkutty
Date: 09/07/2004 10:33AM GMT
ID: 11995258
 Author Comment  


alrite, i managed it,...but :

<logic:iterate name="DateRange" id="Date">
               <c:choose>
                    <c:when test='${Date == 1 || Date == 7}'>
                         hai
                    </c:when>
                    <c:otherwise>
                         hallo
                    </c:otherwise>
               </c:choose>
</logic:iterate>
 
 What type is "Date"?
0
 
LVL 35

Expert Comment

by:girionis
ID: 11995295
Bah.. sorry it seems that I accidentaly copies/pasted the whole page :(

Try this one:

<logic:iterate name="DateRange" id="Date">
               <c:choose>
                    <c:when test='${Date == 1 || Date == 7}'>
                         hai
                    </c:when>
                    <c:otherwise>
                         hallo
                    </c:otherwise>
               </c:choose>
</logic:iterate>
 
 What type is "Date"?
0
 
LVL 32

Author Comment

by:ldbkutty
ID: 11995359
This is my current "struts" tags that is working for one day (sunday):

 <logic:iterate name="DateRange" id="Date">
                <logic:equal name="Date" property="dayOfWeek" value="1">
                      <td id="weekends" class="tdWeekend"> <bean:write name="Date" property="label" /> </td>
                </logic:equal>
                <logic:notEqual name="Date" property="dayOfWeek" value="1">
                      <td class="tdHeader"> <bean:write name="Date" property="label" /> </td>
                </logic:notEqual>
 </logic:iterate>
 
Date is just an "id" for the procedding loop. ( ? )

"DateRange" is the Attribute set in my Action Class as:

request.setAttribute("DateRange", periodSession.getPeriodByDateRange(dateFrom, dateTo));

and getPeriodByDateRange() in my PeriodSession Class returns it as PeriodView[] (View Object).

So, in my PeriodView Class i have :

public final static int SUNDAY = 1;
public final static int MONDAY = 2;
public final static int TUESDAY = 3;
public final static int WEDNESDAY = 4;
public final static int THURSDAY = 5;
public final static int FRIDAY = 6;
public final static int SATURDAY = 7;
      
private String label;
private Date dateFrom;
private Date dateTo;
private int dayOfWeek;

/**
 * Return true if the day is a weekend day
 *  
 * @return boolean
 */
public boolean getIsWeekEndDay(){
      if(dayOfWeek == SUNDAY || dayOfWeek == SATURDAY)
            return true;
      
      return false;
}

/**
 * @return Returns the dayOfWeek.
 */
public int getDayOfWeek() {
      return dayOfWeek;
}
/**
 * @param dayOfWeek The dayOfWeek to set.
 */
public void setDayOfWeek(int dayOfWeek) {
      this.dayOfWeek = dayOfWeek;
}

and so on.
0
 
LVL 32

Author Comment

by:ldbkutty
ID: 11995376
Date is : java.util.Date
0
 
LVL 35

Accepted Solution

by:
girionis earned 200 total points
ID: 11995380
Then do:

<logic:iterate name="DateRange" id="Date">
               <c:choose>
                    <c:when test='${Date.dayOfWeek == 1 || Date.dayOfWeek == 7}'>
                         hai
                    </c:when>
                    <c:otherwise>
                         hallo
                    </c:otherwise>
               </c:choose>
</logic:iterate>
0
 
LVL 35

Expert Comment

by:girionis
ID: 11995398
Hmm.. If it is priovate it won't work :(
0
 
LVL 35

Expert Comment

by:girionis
ID: 11995403
Basically you access the properites by using the . and then the property name of the class, but thwy have to be public.
0
 
LVL 35

Expert Comment

by:girionis
ID: 11995461
On second thought, try it and it might work. I don't remember how exactly it works, it might be through the accessor and mutators that the member variables are exposed.
0
 
LVL 32

Author Comment

by:ldbkutty
ID: 11995726
Ahhh.....everything worked fine after i include:

<%@ page isELIgnored="false"%>

in my JSP. Thanks to all for participating. I will split the points.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 11995759
Thanks ldbkutty :)
0
 
LVL 35

Expert Comment

by:girionis
ID: 11995806
:)
0
 
LVL 16

Expert Comment

by:suprapto45
ID: 11997023
thank you very much. I am sorry that I cannot participate on last message because I am busy working. Anyway, thanks for the points
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now