Re: Dealing with json in wicket

2011-01-19 Thread Marc Nuri (GMail)
Hi
I use a combination of an IRequestTarget implementation and an extended
UrlCodingStrategy.
Regards.
--
Marc Nuri
This is what I use, maybe it helps

public abstract class JSONRequestTarget implements IRequestTarget {
private final RequestParameters requestParameters;

public JSONRequestTarget(RequestParameters requestParameters) {
this.requestParameters = requestParameters;
}

protected abstract JSONArray getJSONData();

@Override
public void respond(RequestCycle requestCycle) {
//Change enconding to support tildes and special characters
requestCycle.getResponse().setContentType(text/html;
charset=utf-8);
requestCycle.getResponse().setCharacterEncoding(utf-8);
requestCycle.getResponse().write(getJSONData().toString());
}

@Override
public void detach(RequestCycle requestCycle) {
//Clean up stuff
requestParameters.setParameters(null);
}

public MapString, ? getParameters() {
return requestParameters.getParameters();
}
}

public abstract class JSONUrlCodingStrategy extends
AbstractRequestTargetUrlCodingStrategy {

public JSONUrlCodingStrategy(final String mountPath) {
super(mountPath);
}

protected abstract JSONRequestTarget
generateRequestTarget(RequestParameters requestParameters);

@Override
public CharSequence encode(IRequestTarget requestTarget) {
if (!(requestTarget instanceof JSONRequestTarget)) {
throw new IllegalArgumentException(This encoder can only be
used with 
+ instances of  + JSONRequestTarget.class.getName());
}
final AppendingStringBuffer url = new AppendingStringBuffer(40);
url.append(getMountPath());
final JSONRequestTarget target = (JSONRequestTarget) requestTarget;
appendParameters(url, new PageParameters(target.getParameters()));
return url;
}

@Override
public IRequestTarget decode(RequestParameters requestParameters) {
return generateRequestTarget(requestParameters);
}

@Override
public boolean matches(IRequestTarget requestTarget) {
boolean ret = false;
if (requestTarget instanceof JSONRequestTarget) {
ret = true;
}
return ret;
}

}





Re: How to use DateTimeField with java.sql.Timestamp

2009-12-17 Thread Marc Nuri (GMail)
You can create a custom converter.

A simpler quick solution is to create two methods to encapsulate the sql
date in a normal date:
The pojo object accepts a java.sql.Timestamp

Your original methods:
[CODE]
  @Column(name = timein  )
  public java.sql.Timestamp getTimein() {
 return timein;
  }

  public void setTimein(java.sql.Timestamp timein) {
 this.timein = timein;
  }

//Add these too:
public java.util.Date getTimeinDate(){
return new java.utilDate(getTimein().getTime());
}
public void setTimeinDate(java.util.Date timeinDate){
setTimein(new java.sql.Timestamp(timeinDate.getTime());
}
[/CODE]

Now you can simply bind to timeinDate and you will get your Timestamp as a
Date.
Hope it helps
--
Marc Nuri


Re: How to use DateTimeField with java.sql.Timestamp

2009-12-17 Thread Marc Nuri (GMail)
I use that continuously. Not only in Wicket but with swing too. It's a kind
of hack but it does its job.
The economic way is to use a converter because in the future you may use the
converter with other model classes. In the other hand if you use the same
model with different technologies (Swing, wicket, reporting...) then you can
always bind a field to known data type.
I use this too when I need to combine two fields in one. If you have a
Person class and name and surname fields, you can add a getter method to
read name+surname and bind that in a read only field or a report.
Cheers.
--
Marc Nuri


Re: Dynamic Query????

2009-07-08 Thread Marc Nuri (GMail)
Have a look at inmethod grid and its datasource interfaces. I use it in one
of my projects to display JPA queries and it works great.Features include
sorting, and inline editing.
--
Marc Nuri


Re: How to avoid code duplication on forms?

2009-05-08 Thread Marc Nuri (GMail)
Hi.
How about using varargs or a similar approach in your TextField:

code
public class ValidatedTextFieldT extends TextFieldT{
public ValidatedTextField(String id, final IModelT model, boolean
required, AbstractValidator... validators)
{
super(id, model);
setRequired(required);
for(AbstractValidator validator : validators){
add(validator);
}
}
}
/code

And the use case:

code
TextField t = new ValidatedTextField(id, new Model(your Model),
true,
EmailAddressValidator.getInstance(),
StringValidator.maximumLength(50));
/code

Maybe you could then use it in a class factory as you suggested. At least it
will shorten a few lines of code.
Best regards.
--
Marc Nuri
http://blog.marcnuri.com
On Fri, May 8, 2009 at 11:14 AM, Christian Helmbold 
christian.helmb...@yahoo.de wrote:


 I think the difference between sub classing and static factory methods is a
 matter of taste in this case.

 If I have many fields, I'd need many classes for them. So I'd group them in
 a sub package. In the case of factory methods I'd group the methods to
 create fields in a class instead of a package.

 Subclass:

 1class UserEmailField extends TextField {
 2  public UserEmailField(String id, IModel model) {
 3super(id, model);
 4setRequired(true);
 5add(EmailAddressValidator.getInstance())
 6add(UniqueValidator.unique(SystemUser.class, email));
 7  }
 8}

 Factory method:

 1public static TextField emailTextField(String id){
 2return (TextField) new TextField(id)
 3.setRequired(true)
 4.add(EmailAddressValidator.getInstance())
 5.add(UniqueValidator.unique(SystemUser.class,
 email));
 6}

 Your answer shows me, that there is no dramatically simpler way to do this.
 If you ignore the two lines for factory class declaration factory methods
 are even a bit shorter. Or is there an advantage of sub classing that I have
 missed?

 Regards,
 Christian



 - Ursprüngliche Mail 
  Von: Igor Vaynberg igor.vaynb...@gmail.com
  An: users@wicket.apache.org
  Gesendet: Freitag, den 8. Mai 2009, 09:08:34 Uhr
  Betreff: Re: How to avoid code duplication on forms?
 
  much simpler
 
  class UserEmailField extends TextField {
public UserEmailField(String id, IModel model) {
  super(id, model);
  add(EmailAddressValidator.getInstance())
  add(UniqueValidator.unique(SystemUser.class, email));
 }
  }





 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org