Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6815659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:50:01+00:00 2026-05-26T20:50:01+00:00

Imagine I have this scenario in my Controller: def nr_1 = params.first_nr def nr_2

  • 0

Imagine I have this scenario in my Controller:

def nr_1 = params.first_nr
def nr_2 = params.second_nr
def result
def erro = 'no'

if(nr_1.isInteger() && nr_2.isInteger())
    result = nr_1.toInteger() * nr_2.toInteger()
else
    erro = 'yes'

if(erro.equals('yes'))
    [sms : 'Please introduce only 2 numbers!']
else
    [sms: 'The result of the multiplication of ' + nr_1 + ' with ' + nr_2 + ' is ' + result]

This is returned to my gsp view and it is successfully done. Now I want to transform this into a REST access Web Service. The way im seeing this, I’ll have to manually create the tags like this:

<firstNumber>nr_1</firstNumber>
<secondNumber>nr_1</secondNumber>   
<result>result</result>  

and then return to the rest request. How can I accomplish this (By providing both HTML and XML response, and for XML, parse only the last XML tags).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:50:01+00:00Added an answer on May 26, 2026 at 8:50 pm

    You can create an object that represent your request and put the content of your request in it.

    class Multiplication
    {
      String nr_1
      String nr_2
      String result
    }
    

    It will enable you to us render as XML to generate your XML in your action:

    def multiplication = new Multiplication(nr_1: params.first_nr,
                                            nr_2: params.second_nr)
    def error = 'no'
      if (multiplication.nr_1.isInteger() && multiplication.nr_2.isInteger())
        multiplication['result'] = multiplication.nr_1.toInteger() * multiplication.nr_2.toInteger()
      else
        error = 'yes'
    
    if (error == 'yes')
    {
      [sms: 'Please introduce only 2 numbers!']
    }
    withFormat {
      html sms: "The result of the multiplication of $multiplication.nr_1 with $multiplication.nr_2 is $multiplication.result"
      xml { render multiplication as XML }
    }
    

    Don’t forget to import grails.converters.* at the beginning of your controller.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine this scenario: You have a desktop and a laptop. The desktop has a
So imagine this scenario, I have a list and it has a bit of
Imagine this scenario: you have a WCF web service that gets hit up to
Imagine this scenario: I have three tables in my database: Products , Users and
Imagine I have this table: Column A | Column B | Column C ------------------------------
Imagine I have this code: var myFunc1 = function(event) { alert(1); } var myFunc2
Imagine i have this HTML snippet 4 times over for four different sections of
Imagine I have a document like this: post = {title: a, comments: [{hour: 08:00,
Imagine I have a template function like this: template<typename Iterator> void myfunc(Iterator a, typename
Imagine I have a recursive algebraic data type like this (Haskell syntax): data Expr

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.