Reply To: Can I pass an Object to a viewscoped bean?

Splash Forums Rewrite Users Can I pass an Object to a viewscoped bean? Reply To: Can I pass an Object to a viewscoped bean?

#26473

I think what you’re doing should be done using a Validator and Converter instead… I think you’re overcomplicating things by doing this all in the .perform() clause:

.addRule()
.when(Direction.isInbound().and(Path.matches("/{artistUrl}")))
.perform(Forward.to("/artist-page.xhtml"))
.where("artistUrl")
   .validatedBy(new Validator() {...do db query to see if object exists...})
   .convertedBy(new Converter() {...do db query to convert string artistUrl to desired object...} )
.bindsTo(El.submissionMethod("#{controller.setArtist}"))

The converter/validator should look up the value in the database and check to see if it’s there. If you need to cache the value so that it’s not looked up twice, then consider using .configuredBy() instead, so that one object handles the validation and conversion of the entire parameter:


public class MyValidatingConverter implements Validator, Converter {
   ...
}

...

MyValidatingConverter configurator = new MyValidatingConverter();

...

.addRule()
.when(Direction.isInbound().and(Path.matches("/{artistUrl}")))
.perform(Forward.to("/artist-page.xhtml"))
.where("artistUrl")
   .configuredBy(configurator)
   .convertedBy(configurator)
.bindsTo(El.submissionMethod("#{controller.setArtist}"))